// mircoApp/lunarCalendar/almanac/almanac.js
const {
  Solar,
  Lunar
} = require("../lunar.js");
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.host,
    curDay: new Date(),
    curDayStr: "",
    dayStr: "",
    yearStr: "",
    weekStr: "",
    ji: "",
    yi: "",
    xi: "",
    fu: "",
    cai: "",
    gui: "",
    yanggui: "",
    yingui: "",
    xing: "",
    sha: "",
    peng: "",
    jiShen: "",
    xiongSha: "",
    tai: "",
    taiSui: "",
    shengXiao: "",
    Lu: "",
    zhiXing: "",

    showDate: false,
    minDate: new Date(2022, 0, 1).getTime(),
    currentDate: new Date().getTime(),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    app._postNetWork({url: app.getNetAddresss('member.login.check-login')});//主要是判断登录和获取底部导航
    if (this.options.data) {
      this.render(this.options.data);
      this.setData({
        isToday: true
      });
      return;
    } 
    this.render();
  },

  render(setDayStr) {
    let obj = {};
    obj.curDay = setDayStr ? new Date(setDayStr) : new Date();
    let d = Lunar.fromDate(obj.curDay);
    let sd = d.getSolar();
    obj.curDayStr = sd.getYear() + "年" + sd.getMonth() + "月" + sd.getDay() + "日";
    obj.dayStr = d.getMonthInChinese() + "月" + d.getDayInChinese();
    obj.yearStr = d.getYearInGanZhi() + "(" + d.getYearShengXiao() + ")年";
    obj.weekStr = "星期" + d.getWeekInChinese();
    obj.ji = d.getDayJi().join(" ");
    obj.yi = d.getDayYi().join(" ");
    obj.xi = d.getDayPositionXiDesc();
    obj.fu = d.getDayPositionFuDesc();
    obj.cai = d.getDayPositionCaiDesc();
    obj.gui = "阳神" + d.getPositionYangGuiDesc() + " 阴神" + d.getPositionYinGuiDesc();
    obj.yanggui = d.getPositionYangGuiDesc();
    obj.yingui = d.getPositionYinGuiDesc();
    obj.xing = d.getGong() + "方" + d.getXiu() + d.getZheng() + d.getAnimal() + "(" + d.getXiuLuck() + ")";
    obj.sha = d.getDayShengXiao() + "日 冲" + d.getDayChongDesc() + " " + d.getDaySha();
    obj.peng = d.getPengZuGan() + " " + d.getPengZuZhi();
    obj.jiShen = d.getDayJiShen().join(" ");
    obj.xiongSha = d.getDayXiongSha().join(" ");
    obj.tai = d.getDayPositionTai();
    obj.taiSui = d.getDayPositionTaiSui() + " " + d.getDayPositionTaiSuiDesc();
    obj.shengXiao = d.getDayShengXiao();
    obj.Lu = d.getDayLu();
    obj.zhiXing = d.getZhiXing();
    this.setData(obj);
  },
  onClickShowDate(){
    this.setData({
      showDate: true
    });
  },
  dateChange(event) {
    if (!event.detail) {
      return;
    }
    this.setData({
      showDate: false
    });
    let selectDate = new Date(event.detail);
    this.render(selectDate);
  },
  subDay() {
    let d = Solar.fromDate(this.data.curDay);
    d = d.next(-1);
    this.render(d.toYmd());
  },
  addDay() {
    let d = Solar.fromDate(this.data.curDay);
    d = d.next(1);
    this.render(d.toYmd());
  },
  onCheck() {
    wx.navigateTo({
      url: `/mircoApp/lunarCalendar/lunarGoodDay/lunarGoodDay`
    });
  },
  onRefresh() {
    wx.redirectTo({
      url: `/mircoApp/lunarCalendar/almanac/almanac`
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})